package com.xr.maintain.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;

/**
 * Created on 2021/8/9
 * @author qiao
 * @Desc:
 */
@Data
public class ResponseBo extends HashMap<String, Object> implements Serializable {
    private static final long serialVersionUID = -8713837118340960775L;

    public ResponseBo() {
    }

    public ResponseBo message(String message) {
        this.put((String)"message", message);
        return this;
    }

    public ResponseBo data(Object data) {
        this.put("data", data);
        return this;
    }

    public ResponseBo put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static  ResponseBo ok() {
         ResponseBo responseBo = new  ResponseBo();
        responseBo.put((String)"message", "操作成功");
        responseBo.put((String)"code", 200);
        return responseBo;
    }

    public static  ResponseBo result(Object rs) {
        return ok().put("data", rs);
    }

    public static  ResponseBo fail() {
         ResponseBo responseBo = new  ResponseBo();
        responseBo.put((String)"message", "操作失败");
        responseBo.put((String)"code", 500);
        return responseBo;
    }

    public static  ResponseBo fail(String msg) {
         ResponseBo responseBo = new  ResponseBo();
        responseBo.put((String)"message", msg);
        responseBo.put((String)"code", 502);
        return responseBo;
    }

    public static  ResponseBo stack(String stack) {
         ResponseBo responseBo = new  ResponseBo();
        responseBo.put((String)"stack", stack);
        responseBo.put((String)"message", "操作失败");
        responseBo.put((String)"code", 502);
        return responseBo;
    }

    public static  ResponseBo warnMsg(String msg) {
         ResponseBo responseBo = new  ResponseBo();
        responseBo.put((String)"message", "操作异常:" + msg);
        responseBo.put((String)"code", 501);
        return responseBo;
    }

    public static  ResponseBo warnData(Object data) {
         ResponseBo responseBo = new  ResponseBo();
        responseBo.put((String)"message", "操作异常");
        responseBo.put((String)"code", 501);
        responseBo.put("data", data);
        return responseBo;
    }

    public static  ResponseBo message(String msg, Integer code) {
         ResponseBo responseBo = new  ResponseBo();
        responseBo.put((String)"message", msg);
        responseBo.put((String)"code", code);
        return responseBo;
    }

    public String getMessage() {
        return String.valueOf(this.get("message"));
    }

    public Object getData() {
        return this.get("data");
    }

    public Integer getCode() {
        return Integer.valueOf(this.get("code").toString());
    }

    public static  ResponseBo cus(Integer value, String msg) {
         ResponseBo responseBo = new  ResponseBo();
        responseBo.put((String)"message", msg);
        responseBo.put((String)"code", value);
        return responseBo;
    }
}
